﻿Public Class FrmMaintenance

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        If MessageBox.Show("确定已更换完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Screwdriver_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Screwdriver_Status = 1

            SaveMaintance(2, MaintainInfo.Screwdriver_preMaintanceTime, MaintainInfo.Screwdriver_Status)
            SaveHistoryMaintance(2, MaintainInfo.Screwdriver_preMaintanceTime, GetMaintanceName(2))
        End If
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        If MessageBox.Show("确定已更换完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Nozzle_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Nozzle_Status = 1
            SaveMaintance(4, MaintainInfo.Nozzle_preMaintanceTime, MaintainInfo.Nozzle_Status)
            SaveHistoryMaintance(4, MaintainInfo.Nozzle_preMaintanceTime, GetMaintanceName(4))
        End If
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        If MessageBox.Show("确定已检查完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Cable_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Cable_Status = 1
            'If newset(7) Then
            '    Dim data As String = MaintainInfo.Screw_Feeder & "," & MaintainInfo.Feeder_Datatime & "," & MaintainCycle.ScrewFeederChange & "," & MaintainInfo.Electric_Mouth & "," & MaintainInfo.Screwdriver_Datatime & "," & MaintainCycle.ScrewChange & "," & MaintainInfo.Relay & "," & MaintainInfo.Relay_Datatime & "," & MaintainCycle.RelayChange & "," & MaintainInfo.Nozzle_datatime & "," & MaintainInfo.Nozzle_Judge & "," & MaintainCycle.NozzleChange & "," & MaintainInfo.Screw_Datatime & "," & MaintainInfo.Screw_Judge & "," & MaintainCycle.ScrewDays & "," & MaintainInfo.Plug_Datatime & "," & MaintainInfo.Plug_Judge & "," & MaintainCycle.HeadCableDays & "," & MaintainInfo.Blet_Datatime & "," & MaintainInfo.Blet_Judge & "," & MaintainCycle.BletDays & "," & MaintainInfo.Strainer_Datatime & "," & MaintainInfo.Strainer_Judge & "," & MaintainCycle.CleanVacuumDays & "," & MaintainInfo.Screw_Feeder_Datatime & "," & MaintainInfo.Screw_Feeder_Judge & "," & MaintainCycle.CleanScrewFeederDays & ","
            '    UploadMessage(data, "Maintain_message")
            'End If
            SaveMaintance(6, MaintainInfo.Cable_preMaintanceTime, MaintainInfo.Cable_Status)
            SaveHistoryMaintance(6, MaintainInfo.Cable_preMaintanceTime, GetMaintanceName(6))
        End If
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        If MessageBox.Show("确定已更换完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Motor_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Motor_Status = 1
            'If newset(7) Then
            '    Dim data As String = MaintainInfo.Screw_Feeder & "," & MaintainInfo.Feeder_Datatime & "," & MaintainCycle.ScrewFeederChange & "," & MaintainInfo.Electric_Mouth & "," & MaintainInfo.Screwdriver_Datatime & "," & MaintainCycle.ScrewChange & "," & MaintainInfo.Relay & "," & MaintainInfo.Relay_Datatime & "," & MaintainCycle.RelayChange & "," & MaintainInfo.Nozzle_datatime & "," & MaintainInfo.Nozzle_Judge & "," & MaintainCycle.NozzleChange & "," & MaintainInfo.Screw_Datatime & "," & MaintainInfo.Screw_Judge & "," & MaintainCycle.ScrewDays & "," & MaintainInfo.Plug_Datatime & "," & MaintainInfo.Plug_Judge & "," & MaintainCycle.HeadCableDays & "," & MaintainInfo.Blet_Datatime & "," & MaintainInfo.Blet_Judge & "," & MaintainCycle.BletDays & "," & MaintainInfo.Strainer_Datatime & "," & MaintainInfo.Strainer_Judge & "," & MaintainCycle.CleanVacuumDays & "," & MaintainInfo.Screw_Feeder_Datatime & "," & MaintainInfo.Screw_Feeder_Judge & "," & MaintainCycle.CleanScrewFeederDays & ","
            '    UploadMessage(data, "Maintain_message")
            'End If
            SaveMaintance(3, MaintainInfo.Motor_preMaintanceTime, MaintainInfo.Motor_Status)
            SaveHistoryMaintance(3, MaintainInfo.Motor_preMaintanceTime, GetMaintanceName(3))
        End If
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        If MessageBox.Show("确定已检查完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Blet_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Blet_Status = 1
            'If newset(7) Then
            '    Dim data As String = MaintainInfo.Screw_Feeder & "," & MaintainInfo.Feeder_Datatime & "," & MaintainCycle.ScrewFeederChange & "," & MaintainInfo.Electric_Mouth & "," & MaintainInfo.Screwdriver_Datatime & "," & MaintainCycle.ScrewChange & "," & MaintainInfo.Relay & "," & MaintainInfo.Relay_Datatime & "," & MaintainCycle.RelayChange & "," & MaintainInfo.Nozzle_datatime & "," & MaintainInfo.Nozzle_Judge & "," & MaintainCycle.NozzleChange & "," & MaintainInfo.Screw_Datatime & "," & MaintainInfo.Screw_Judge & "," & MaintainCycle.ScrewDays & "," & MaintainInfo.Plug_Datatime & "," & MaintainInfo.Plug_Judge & "," & MaintainCycle.HeadCableDays & "," & MaintainInfo.Blet_Datatime & "," & MaintainInfo.Blet_Judge & "," & MaintainCycle.BletDays & "," & MaintainInfo.Strainer_Datatime & "," & MaintainInfo.Strainer_Judge & "," & MaintainCycle.CleanVacuumDays & "," & MaintainInfo.Screw_Feeder_Datatime & "," & MaintainInfo.Screw_Feeder_Judge & "," & MaintainCycle.CleanScrewFeederDays & ","
            '    UploadMessage(data, "Maintain_message")
            'End If
            SaveMaintance(7, MaintainInfo.Blet_preMaintanceTime, MaintainInfo.Blet_Status)
            SaveHistoryMaintance(7, MaintainInfo.Blet_preMaintanceTime, GetMaintanceName(7))
        End If
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        If MessageBox.Show("确定已保养完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Clean_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Clean_Status = 1
            'If newset(7) Then
            '    Dim data As String = MaintainInfo.Screw_Feeder & "," & MaintainInfo.Feeder_Datatime & "," & MaintainCycle.ScrewFeederChange & "," & MaintainInfo.Electric_Mouth & "," & MaintainInfo.Screwdriver_Datatime & "," & MaintainCycle.ScrewChange & "," & MaintainInfo.Relay & "," & MaintainInfo.Relay_Datatime & "," & MaintainCycle.RelayChange & "," & MaintainInfo.Nozzle_datatime & "," & MaintainInfo.Nozzle_Judge & "," & MaintainCycle.NozzleChange & "," & MaintainInfo.Screw_Datatime & "," & MaintainInfo.Screw_Judge & "," & MaintainCycle.ScrewDays & "," & MaintainInfo.Plug_Datatime & "," & MaintainInfo.Plug_Judge & "," & MaintainCycle.HeadCableDays & "," & MaintainInfo.Blet_Datatime & "," & MaintainInfo.Blet_Judge & "," & MaintainCycle.BletDays & "," & MaintainInfo.Strainer_Datatime & "," & MaintainInfo.Strainer_Judge & "," & MaintainCycle.CleanVacuumDays & "," & MaintainInfo.Screw_Feeder_Datatime & "," & MaintainInfo.Screw_Feeder_Judge & "," & MaintainCycle.CleanScrewFeederDays & ","
            '    UploadMessage(data, "Maintain_message")
            'End If
            SaveMaintance(8, MaintainInfo.Clean_preMaintanceTime, MaintainInfo.Clean_Status)
            SaveHistoryMaintance(8, MaintainInfo.Clean_preMaintanceTime, GetMaintanceName(8))
        End If
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        If MessageBox.Show("确定已检查完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Screw_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Screw_Status = 1
            SaveMaintance(5, MaintainInfo.Screw_preMaintanceTime, MaintainInfo.Screw_Status)
            SaveHistoryMaintance(5, MaintainInfo.Screw_preMaintanceTime, GetMaintanceName(5))
        End If
    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        If MessageBox.Show("确定已保养完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Robot_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Robot_Status = 1
            'If newset(7) Then
            '    Dim data As String = MaintainInfo.Screw_Feeder & "," & MaintainInfo.Feeder_Datatime & "," & MaintainCycle.ScrewFeederChange & "," & MaintainInfo.Electric_Mouth & "," & MaintainInfo.Screwdriver_Datatime & "," & MaintainCycle.ScrewChange & "," & MaintainInfo.Relay & "," & MaintainInfo.Relay_Datatime & "," & MaintainCycle.RelayChange & "," & MaintainInfo.Nozzle_datatime & "," & MaintainInfo.Nozzle_Judge & "," & MaintainCycle.NozzleChange & "," & MaintainInfo.Screw_Datatime & "," & MaintainInfo.Screw_Judge & "," & MaintainCycle.ScrewDays & "," & MaintainInfo.Plug_Datatime & "," & MaintainInfo.Plug_Judge & "," & MaintainCycle.HeadCableDays & "," & MaintainInfo.Blet_Datatime & "," & MaintainInfo.Blet_Judge & "," & MaintainCycle.BletDays & "," & MaintainInfo.Strainer_Datatime & "," & MaintainInfo.Strainer_Judge & "," & MaintainCycle.CleanVacuumDays & "," & MaintainInfo.Screw_Feeder_Datatime & "," & MaintainInfo.Screw_Feeder_Judge & "," & MaintainCycle.CleanScrewFeederDays & ","
            '    UploadMessage(data, "Maintain_message")
            'End If
            SaveMaintance(9, MaintainInfo.Robot_preMaintanceTime, MaintainInfo.Robot_Status)
            SaveHistoryMaintance(9, MaintainInfo.Robot_preMaintanceTime, GetMaintanceName(9))
        End If
    End Sub

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        If MessageBox.Show("确定已更换完毕吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes Then
            MaintainInfo.Feeder_preMaintanceTime = DateAndTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
            MaintainInfo.Feeder_Status = 1
            SaveMaintance(1, MaintainInfo.Feeder_preMaintanceTime, MaintainInfo.Feeder_Status)
            SaveHistoryMaintance(1, MaintainInfo.Feeder_preMaintanceTime, GetMaintanceName(1))
        End If
    End Sub
    ''' <summary>
    ''' 保存历史维护记录
    ''' </summary>
    ''' <param name="MaintanceType"></param>
    ''' <param name="MaintanceTime"></param>
    ''' <remarks></remarks>
    Private Sub SaveHistoryMaintance(ByVal MaintanceType As Integer, ByVal MaintanceTime As String, ByVal MaintanceName As String)
        Dim sql As String = "insert into MaintainaceHis" & "(MaintanceType,MaintanceTime,MaintanceName)values(" & MaintanceType & "," & "'" & MaintanceTime & "'" & "," & "'" & MaintanceName & "'" & ")"
        HandleMysql(sql)
    End Sub
    ''' <summary>
    ''' 保存保养信息
    ''' </summary>
    ''' <param name="MaintanceType"></param>
    ''' <param name="MaintanceTime"></param>
    ''' <remarks></remarks>
    Public Sub SaveMaintance(ByVal MaintanceType As Integer, ByVal MaintanceTime As String, ByVal status As String)
        Dim sql As String = ""
        sql = "update Maintainace" & " set MaintanceTime=" & "'" & MaintanceTime & "'" & ",Status=" & status & " where MaintanceType=" & MaintanceType
        HandleMysql(sql)
    End Sub
    Private Function GetMaintanceName(ByVal MaintanceType As Integer) As String
        Dim sql As String = "select * from Maintainace where MaintanceType = " & MaintanceType
        Dim ds As DataSet = New DataSet
        ds = SearchMysql(sql)
        If ds.Tables(0).Rows.Count > 0 Then
            Return ds.Tables(0).Rows(0)("MaintanceName").ToString
        Else
            Return ""
        End If
    End Function
End Class